package com.zkingsoft.actions.app.interfaces;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.constraint.BaseController;
import com.zkingsoft.model.distribution.DisClassicCase;
import com.zkingsoft.model.distribution.DisDesignerWorks;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.services.distribution.DisClassicCaseService;
import com.zkingsoft.services.distribution.DisDesignerWorksService;
import com.zkingsoft.util.WebUtil;

@Controller
@RequestMapping(value = "app/works")
public class AppWorksController extends BaseController {

	@Resource
	private DisDesignerWorksService workService;

	@Resource
	private DisClassicCaseService caseService;
	
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(PaginationVO pageVo) {
		if (pageVo == null) {
			pageVo = new PaginationVO();
		}
		pageVo.setLimit(0);
		pageVo.setSort("work_create_time");
		pageVo.setOrder("desc");
		List<DisDesignerWorks> dataList = workService.findInPage(null, pageVo);
		AjaxResult result = new AjaxResult(AjaxResult.STATUS_OK, dataList);
		return result;
	}

	/**
	 * 查看作品详情
	 */
	@RequestMapping(value = "/toDetail")
	public String toDetail(Long workId) {
		DisDesignerWorks work = workService.findById(workId);
		int viewtimes = work.getWorkViewTimes();
		viewtimes++;
		work.setWorkViewTimes(viewtimes);
		workService.modifyByModel(work);

		WebUtil.setRequestAttribute("work", work);
		return "app/works/works_detail";
	}

	/**
	 * 
	 */
	@RequestMapping(value = "/showCaseList")
	public @ResponseBody AjaxResult showCaseList(PaginationVO pageVo) {
		if (pageVo == null) {
			pageVo = new PaginationVO();
		}
		pageVo.setLimit(0);
		pageVo.setSort("case_create_time");
		pageVo.setOrder("desc");
		List<DisClassicCase> dataList = caseService.findInPage(null, pageVo);
		AjaxResult result = new AjaxResult(AjaxResult.STATUS_OK, dataList);
		return result;
	}

	/**
	 * 查看案例详情
	 */
	@RequestMapping(value = "/toCaseDetail")
	public String toCaseDetail(Long caseId) {
		DisClassicCase caseDetail =  caseService.findById(caseId);
		int viewtimes = caseDetail.getCaseViewTimes();
		viewtimes++;
		caseDetail.setCaseViewTimes(viewtimes);
		caseService.modifyByModel(caseDetail);

		WebUtil.setRequestAttribute("caseDetail", caseDetail);
		return "app/works/case_detail";
	}

	
}
